<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head lang="en" th:replace="include/common/common :: commonHeader">
    <footer th:include="include/common/common :: layUiResource"></footer>
    <footer th:include="include/common/common :: blueCSSResource"></footer>

    <script>
        layui.config({
            base: '/staticResource/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index' , 'table'] , function () {
            var table = layui.table
                ,admin = layui.admin
                ,element = layui.element;

            let entityName = 'dictData'
                ,pageSize = [[${pageSize}]]
                ,_orgCode = $('#orgCode').val()
                ,tableId = entityName + "-table-operate"
                ,cols = [
                [
                    {type:'checkbox', fixed: 'left'}
                    ,{field:'id', title: 'ID', sort: true, hide:true, fixed: 'left'}
                    ,{field:'dictLabel', sort:true , title: '字典标签'}
                    ,{field:'dictValue', sort:true , title: '字典键值'}
                    ,{field:'isSys', sort:true , title: '系统字典' , templet:function (d) {
                        let msg = "否";
                        if (d.isSys == '1'){
                            msg = "是";
                        }
                        return msg;}}
                    ,{field:'sort', sort:true , title: '排序'}
                    ,{field:'updateDate', sort:true , title: '更新时间'}
                    ,{title:'操作' , align:'center', fixed: 'right', toolbar: '#test-table-operate-barDemo'}
                ]
            ];

            $(document).on('click' , '#' + entityName + 'SearchBtn' , function () {
                $.fn.blueJs.tools.active['layTable'].call(this , table , this , pageSize , cols , tableId);
            });

            $(document).ready(function () {
                let searchBtn = '#' + entityName + 'SearchBtn';
                $.fn.blueJs.tools.active['layTable'].call(this , table , searchBtn , pageSize , cols , tableId);
            });

            //监听工具条

            //todo:以下测试，未完成
            //监听表格复选框选择
            table.on('checkbox(' + entityName + '-table-operate)', function(obj){
                console.log(obj)
            });

            table.on('tool(' + entityName + '-table-operate)', function(obj){
                var data = obj.data;
                if(obj.event === 'data'){
                    let i = "/a/" + entityName + "/dataList?id=" + data.dictType , t = "字典数据管理";
                    $.fn.blueJs.tools.active['layerOpen'].call(this , i , t);
                } else if(obj.event === 'edit'){
                    let i = "/a/dict/form2Data?id=" + data.id , t = "编辑字典";
                    $.fn.blueJs.tools.active['layerOpen'].call(this , i , t);
                }
            });

            var active = {
                getCheckData: function(){ //获取选中数据
                    var checkStatus = table.checkStatus('test-table-operate')
                        ,data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
                ,getCheckLength: function(){ //获取选中数目
                    var checkStatus = table.checkStatus('test-table-operate')
                        ,data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                }
                ,add: function(){
                    layui.router();
                    let dictType = $("#dictType").val();
                    let url = "/a/dict/form2Data?isNewRecord=true&orgCode=" + _orgCode;
                    url = url + "&dictType=" + dictType;
                    let i = url, t = "新增字典";
                    $.fn.blueJs.tools.active['layerOpen'].call(this , i , t);
                }
            };

            $('.test-table-operate-btn .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">字典管理</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space10 layui-form-item">
                        <!--                        todo:id = entity + search + form-->
                        <form class="layui-form" id="dictDataSearchForm" th:object="${dictData}" method="post" action="/a/dict/findPage2Data">
                            <input type="hidden" id="dictType" name="dictType" th:field="*{dictType}"/>
                            <input type="hidden" id="orgCode" name="orgCode" th:field="*{orgCode}"/>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">字典标签：</label>
                                    <div class="layui-inline">
                                        <input type="text" name="dictLabel" id="searchDictLabel" placeholder="字典标签" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">字典键值：</label>
                                    <div class="layui-inline">
                                        <input type="text" name="dictValue" id="searchDictValue" placeholder="字典键值" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <!--                        todo:blue-form-id = entity + search + form-->
                                <button type="button" class="layui-btn" id="dictDataSearchBtn" onsubmit="return false" blue-form-id="dictDataSearchForm">搜索</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-body" >
                    <div class="layui-btn-group test-table-operate-btn" id="tableBtn" style="margin-bottom: 10px;">
                        <button class="layui-btn layui-btn-sm" data-type="add">新增</button>
                        <button class="layui-btn layui-btn-sm" data-type="getCheckData">获取选中行数据</button>
                        <button class="layui-btn layui-btn-sm" data-type="getCheckLength">获取选中数目</button>
                    </div>
                    <table class="layui-hide" id="dictData-table-operate" lay-filter="dict-table-operate"></table>

                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
<!--                        <a class="layui-btn layui-btn-xs" lay-event="data">数据字典</a>-->
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
</html>